import Vue from "vue";
import Vuex from 'vuex'

import app from "@/store/modules/app";
import getters from "@/store/getters";

Vue.use(Vuex)

export default new Vuex.Store({
    modules: {
        app
    },
    state: {
        sysInfo: {
            logo: '',
            domainRegistrationInfo: "",
            theme: "",
            name: "",
            bgImg: ''
        },
        worksheetList: [],
        tableMenuExtend: true,
        nodeDefinitions: {
            action: {},
            trigger: {},
        },
        appAuths:{},
        userInfo:{}
    },
    mutations: {
        updateSysTheme(state, value){
            state.sysInfo.theme = value
        },
        updateNodeDefinitions(state, value){
            state.nodeDefinitions = value
        },
        updateSysInfo(state, value){
            let link = document.getElementById('icon')
            link.href = value.logo
            if(value.theme === '') value.theme = 'cgs_light'
            state.sysInfo = value
        },
        updateWorksheetList(state, value){
            state.worksheetList = value
        },
        updateWorksheetName(state, value){
            state.worksheetList.find(list => list.id === value.id).name = value.name
        },
        
        updateWorksheetIcon(state, value){
            state.worksheetList.find(list => list.id === value.id).icon = value.icon
        },
        updateWorksheetHidden(state, value){
            state.worksheetList.find(list => list.id === value.id).hidden = value.hidden
        },
        deleteWorksheet(state, value){
            state.worksheetList = state.worksheetList.filter(w => w.id !== value)
        },
        updateTableMenuExtend(state, value){
            state.tableMenuExtend = !state.tableMenuExtend
        },
        updateAppAuths(state, value){
            state.appAuths = value
        },
        updateUserInfo(state, value){
            state.userInfo = value
        },
    },
    actions: {
    },
    getters
})
